package org.py;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.EventListener;


@SpringBootApplication()
@MapperScan(basePackages = "org.py.mapper")
public class InitApplication {

    private final ApplicationContext applicationContext;

    public InitApplication(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }
    
    public static void main(String[] args) {
        SpringApplication.run(InitApplication.class, args);
    }

    @EventListener
    public void onWebServerInitialized(WebServerInitializedEvent event) {
        int port = event.getWebServer().getPort();
        String contextPath = ((ServletWebServerApplicationContext) applicationContext).getServletContext().getContextPath();
        System.out.println("Spring Boot 应用程序启动成功");
        System.out.println("您可以通过：http://127.0.0.1:"+port+contextPath+"/monitor/test 测试应用是否完全成功");
    }
}

